﻿using System.Collections.Generic;
using Application.DTO;
using DomainModel.PDC;
using DomainModel.Support;
using Infrastructure.DC;

namespace Application.Task
{
    public class CreateNewCustomer
    {
        private CustomerInfo _customerInfo;
        private ICustomersDao _customersDao;
        public IEnumerable<BrokenBusinessRuleInfo> BrokenRules { get; private set; }
        public bool Succes { get; set;}
        public CreateNewCustomer(CustomerInfo customerInfo)
            : this(customerInfo, new CustomersDao())
        {
        }

        public CreateNewCustomer(CustomerInfo customerInfo, ICustomersDao customersDao)
        {
            _customerInfo = customerInfo;
            _customersDao = customersDao;
        }
        public void Execute()
        {
            
            Customer customer  = new CustomerFactory().From(_customerInfo);
            List<BrokenBusinessRule> brokenRules = customer.GetBrokenRules();
            if (brokenRules.Count == 0)
             {
                
                 _customersDao.Save(customer);
                 Succes = true;
             }
            else
            {
                BrokenRules = new BrokenBusinessRuleInfoMapper().From(brokenRules);
                Succes = false;
            }

        }
    }
}
